

<div id="rbac_admin_save">
    <form>
        <zrow>

            <zcol :md="6">
                <zinput label="username" name="username" :ctx="this"/>
            </zcol>

        </zrow>


        <zrow>
            <zcol :md="6">
                <zinput label="email" name="email" :ctx="this"/>
            </zcol>

        </zrow>

        <zrow>


            <zcol :md="6">
                <zinput label="password" name="password" :ctx="this"/>
            </zcol>
        </zrow>

        <zrow>

            <zcol :md="12">
                <zcheckbox label="角色" name="roles" :ctx="this" :data="roles"/>
            </zcol>
        </zrow>

        <a @click="submit" class="btn btn-primary">提交</a>
    </form>

</div>

<script>
    new Vue({
        el:'#rbac_admin_save',
        mounted:function(){
            var _this = this ;
            if(this.editData){
                copyProperty(this.editData,this.form) ;
            }

            this.state.status = 'mounted'

            zhttp.get('rbac/admin/roles',{uid:App.url().param('id')}).then(function (data) {
                var rs = []
                data.map(function (d) {
                    rs.push({label:d.name,value:d.id})
                })
                _this.roles = rs
                //_this.$forceUpdate();
            })
        },
        data:{
            state:{
                status:''
            },
            roles:[],
            form:{
                username:'',
                email:'',
                password:'',
                roles:[]
            },
            validate:{
                name:[Va.required],
                email:[Va.required],

            },
            editData:<?=$data?>
    },
    methods:{
        submit:function(){
            if(!validateAll(this)){
                return
            }

            var id = App.url().param('id') || '' ;

            zhttp.post('rbac/admin/save?id='+id,this.form,function (d) {
                if(d.code == 0){
                    success('操作成功')
                    //Loader.getDialog('rbac/Admin/save').close()
                    go('rbac/admin/index')
                }else{

                }
                return false ;
            })
        }
    }
    })
</script>